home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Culturalia+IMDB.ifs < prev    next >
Text File  |  2005-05-05  |  12KB  |  389 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=David Arenillas, Antoine Potten and J.M. Folgueira
  8. Title=Culturalia(+IMDB)
  9. Description=Movie importation script for Culturalia and IMDB
  10. Site=http://www.culturalianet.com
  11. Language=ES
  12. Version=1.5 (05 Feb 2005)
  13. Requires=3.5.0
  14. Comments=Several updates made by: folgui (folgui@bigfoot.com), RedDwarf, Hades666, KaBeCi, PolloPolea, Moises DΘniz.||Thanks to Culturalia's webmaster for his help and for providing more direct access to his database.||
  15. License=The source code of the script can be used in another program only if full credits to script author and a link to Ant Movie Catalog website are given in the About box or in the documentation of the program.
  16. GetInfo=1
  17.  
  18. [Options]
  19. ImportLengthIMDB=0|0|0=Imports Length from Culturalia (no info)|1=Imports Length from IMDB
  20. ImportRatingIMDB=0|0|0=Imports Rating from Culturalia (no info)|1=Imports Rating from IMDB
  21. BatchMode=0|0|0=Normal working mode, prompts user when needed|1=Does not display any window, takes the first movie found
  22.  
  23. ***************************************************)
  24.  
  25. program Culturalia_IMDB;
  26. uses
  27.   StringUtils1;
  28. const
  29.   BaseURLCulturalia = 'http://www.culturalianet.com/bus/catalogo.php';
  30. var
  31.   MovieName, strTemp, donde: string;
  32.   Articles: array of string;
  33.   Index: integer;
  34.  
  35. procedure AnalyzePageIMDB(Address: string);
  36. var
  37.   PageText: string;
  38.   Value: string;
  39. begin
  40.   PageText := GetPage(Address);
  41.   if pos('<title>IMDb', PageText) = 0 then
  42.   begin
  43.     AnalyzeMoviePageIMDB(PageText)
  44.   end else
  45.   begin
  46.     if Pos('<b>No Matches.</b>', PageText) > 0 then
  47.     begin
  48.       if GetOption('BatchMode') = 0 then
  49.         ShowMessage('No se ha encontrado ninguna coincidencia');
  50.       Exit;
  51.     end;
  52.     if GetOption('BatchMode') > 0 Then
  53.     begin
  54.       Value := TextBetween(PageText, '<ol><li>', '</li><li>');
  55.       Address := TextBetween(Value, '<a href="', '">');
  56.       AnalyzePageIMDB(Address);
  57.     end else
  58.     begin
  59.       PickTreeClear;
  60.       repeat
  61.         Value := TextBefore(PageText, '<ol>', '<b>');
  62.         if Value <> '' then
  63.         begin
  64.           HTMLRemoveTags(Value);
  65.           HTMLDecode(Value);
  66.           PickTreeAdd(Value, '');
  67.         end;
  68.         Value := TextBetween(PageText, '<ol>', '</ol>');
  69.         PageText := RemainingText;
  70.       until not AddMovieTitles(Value);
  71.       Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
  72.       if Value <> '' then
  73.         PickTreeMoreLink('http://us.imdb.com' + Value);
  74.       if PickTreeExec(Address) then
  75.         AnalyzePageIMDB(Address);
  76.     end;
  77.   end;
  78. end;
  79.  
  80. procedure AnalyzeMoviePageIMDB(PageText: string);
  81. var
  82.   Value: string;
  83. begin
  84.   // Rating
  85.   if (GetOption('ImportRatingIMDB') = 1) then
  86.   begin
  87.    Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/');
  88.    SetField(fieldRating, TextBetween(Value, '<b>', '/'));
  89.   end;
  90.  
  91.   // Length
  92.   if (GetOption('ImportLengthIMDB') = 1) then
  93.   begin
  94.     Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' ');
  95.     if Value <> '' then
  96.     begin
  97.       if Pos(':', Value) > 0 then
  98.         SetField(fieldLength, TextAfter(Value, ':'))
  99.       else
  100.         SetField(fieldLength, Value);
  101.     end;
  102.   end;
  103. end;
  104.  
  105. function AddMovieTitles(List: string): Boolean;
  106. var
  107.   Value: string;
  108.   Address: string;
  109. begin
  110.   Result := False;
  111.   Value := TextBetween(List, '<li>', '</li>');
  112.   List := RemainingText;
  113.   while Value <> '' do
  114.   begin
  115.     Address := TextBetween(Value, '<a href="', '">');
  116.     HTMLRemoveTags(Value);
  117.     HTMLDecode(Value);
  118.     PickTreeAdd(Value, Address);
  119.     Result := True;
  120.     Value := TextBetween(List, '<li>', '</li>');
  121.     List := RemainingText;
  122.   end;
  123. end;
  124.  
  125. function TransformTitle(Title: string): string;
  126. var
  127.   BeginPos, EndPos: Integer;
  128.   Value: string;
  129.   Words: array of string;
  130.   Articles: array of string;
  131.   Replace,Original: string;
  132.   Index, CommaCount: Integer;
  133. Begin
  134.   // Original Title
  135.   Result:=Title;
  136.  
  137.   Setarraylength(Words,11);
  138.   Words[0]:=' In ';
  139.   Words[1]:=' On ';
  140.   Words[2]:=' Of ';
  141.   Words[3]:=' As ';
  142.   Words[4]:=' The ';
  143.   Words[5]:=' At ';
  144.   Words[6]:=' And A ';
  145.   Words[7]:=' And ';
  146.   Words[8]:=' An ';
  147.   Words[9]:=' To ';
  148.   Words[10]:=' For ';
  149.  
  150.   SetArrayLength(Articles,35);
  151.   Articles[0]:=' The';
  152.   Articles[1]:=' a';
  153.   Articles[2]:=' An';
  154.   Articles[3]:=' Le';
  155.   Articles[4]:=' L''';
  156.   Articles[5]:=' Les';
  157.   Articles[6]:=' Der';
  158.   Articles[7]:=' Das';
  159.   Articles[8]:=' Die';
  160.   Articles[9]:=' Des';
  161.   Articles[10]:=' Dem';
  162.   Articles[11]:=' Den';
  163.   Articles[12]:=' Ein';
  164.   Articles[13]:=' Eine';
  165.   Articles[14]:=' Einen';
  166.   Articles[15]:=' Einer';
  167.   Articles[16]:=' Eines';
  168.   Articles[17]:=' Einem';
  169.   Articles[18]:=' Il';
  170.   Articles[19]:=' Lo';
  171.   Articles[20]:=' La';
  172.   Articles[21]:=' I';
  173.   Articles[22]:=' Gli';
  174.   Articles[23]:=' Le';
  175.   Articles[24]:=' Uno';
  176.   Articles[25]:=' Una';
  177.   Articles[26]:=' Un''';
  178.   Articles[27]:=' O';
  179.   Articles[28]:=' Os';
  180.   Articles[29]:=' As';
  181.   Articles[30]:=' El';
  182.   Articles[31]:=' Los';
  183.   Articles[32]:=' Las';
  184.   Articles[33]:=' Unos';
  185.   Articles[34]:=' Unas';
  186.  
  187.   // Count the Comma in The Title
  188.   CommaCount := 0;
  189.   EndPos := 0;
  190.   Value := Title;
  191.   repeat
  192.      BeginPos := Pos(',', Value);
  193.      if BeginPos > 0 then
  194.      begin
  195.        Delete(Value, 1, BeginPos);
  196.        CommaCount := CommaCount + 1;
  197.        EndPos := EndPos + BeginPos;
  198.      end;
  199.   until( Pos(',',Value) = 0);
  200.  
  201.   // Compare the Article to a list of known ones
  202.   for Index := 0 to 34 do
  203.   begin
  204.     if Pos(Articles[Index], Value) <> 0 then
  205.     begin
  206.        CommaCount := 1;
  207.        BeginPos := EndPos;
  208.        Break;
  209.     end;
  210.   end;
  211.  
  212.   if (BeginPos > 0) and (CommaCount = 1) then
  213.   begin
  214.     Value := Copy(Title, BeginPos + 1, Length(Title));
  215.     Value := Trim(Value);
  216.     Result := Value + ' ' + Copy(Title, 1, BeginPos - 1);
  217.   end;
  218.  
  219.   BeginPos := Pos(': ', Result);
  220.   if BeginPos > 0 then
  221.     Result := StringReplace(Result, ': ', ' - ');
  222.  
  223.   Result := AnsiMixedCase(Result, ' ');
  224.  
  225.   for Index := 0 to 10 do
  226.   begin
  227.     if Pos(Words[Index],Result) <> 0 then
  228.     begin
  229.       Original := Words[Index];
  230.       Replace := AnsiLowerCase(Original);
  231.       Result := StringReplace(Result, Original, Replace);
  232.     end;
  233.   end;
  234.  
  235.   Result := StringReplace(Result, ' - the ', ' - The ');
  236.   Result := Trim(Result);
  237. end;
  238.  
  239. procedure AnalyzePageCulturalia(Address: string);
  240. var
  241.   Page, TempTit: TStringList;
  242.   LineNr: Integer;
  243.   Code, Title, TitleOrig, Year: string;
  244.   TitleFound: Boolean;
  245. begin
  246.   Page := TStringList.Create;
  247.   TempTit := TStringList.Create;
  248.   Page.Text := GetPage(Address);
  249.   Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  250.   if Pos('No se ha encontrado ning·n artφculo por tφtulo', Page.Text) = 0 then
  251.   begin
  252.     if GetOption('BatchMode') = 0 then
  253.     begin
  254.        PickTreeClear;
  255.        LineNr := 1;
  256.        PickTreeAdd('Resultados mßs probables de la b·squeda:', '');
  257.        while LineNr + 3 < Page.Count do
  258.        begin
  259.          Code := TextAfter(Page.GetString(LineNr), 'Codigo = ');
  260.          Title := TextAfter(Page.GetString(LineNr+1), 'Titulo = ');
  261.          TitleOrig := TextAfter(Page.GetString(LineNr+2), 'Titulo original = ');
  262.          Year := TextAfter(Page.GetString(LineNr+3), 'A±o = ');
  263.          PickTreeAdd(Title + ' (' + TitleOrig + '), ' + Year, BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
  264.          LineNr := LineNr + 5;
  265.        end;
  266.        Page.Free;
  267.        if PickTreeExec(Address) then
  268.          AnalyzeMoviePageCulturalia(Address);
  269.     end else
  270.     begin
  271.       LineNr := 1;
  272.       TitleFound := True;
  273.       Code := TextAfter(Page.GetString(LineNr), 'Codigo = ');
  274.       Address := (BaseURLCulturalia + '?catalogo=1&codigo=' + Code);
  275.       if TitleFound then
  276.         AnalyzeMoviePageCulturalia(Address);
  277.       Page.Free;
  278.     end;
  279.   end else
  280.   if (GetOption('BatchMode') = 0) then
  281.     ShowMessage('No se ha encontrado ninguna coincidencia por tφtulo');
  282. end;
  283.  
  284. procedure AnalyzeMoviePageCulturalia(Address: string);
  285. var
  286.   Page: TStringList;
  287.   Comments: string;
  288.   strTitle: string;
  289.   strSinopsis: string;
  290.   Line: string;
  291.   LineNr: Integer;
  292.   strTemp: string;
  293. begin
  294.   Page := TStringList.Create;
  295.   Page.Text := StringReplace(GetPage(Address), '<br><br>', #13#10);
  296.   Page.Text := StringReplace(Page.Text, '<br>', #13#10);
  297.   strTitle := TextAfter(Page.GetString(1), 'Titulo = ');
  298.   if copy(strTitle, Length(strTitle), Length(strTitle)) = '.' then
  299.   begin
  300.     strTemp := Copy(strTitle, 1, Length(strTitle) -1);
  301.   end else
  302.   begin
  303.     strTemp := strTitle;
  304.   end;
  305.   SetField(fieldTranslatedTitle, TransformTitle(strTemp));
  306.   strTemp := TextAfter(Page.GetString(2), 'Titulo original = ');
  307.   SetField(fieldOriginalTitle, TransformTitle(strTemp));
  308.   SetField(fieldYear, TextAfter(Page.GetString(3), 'A±o = '));
  309.   SetField(fieldCategory, TextAfter(Page.GetString(4), 'Genero = '));
  310.   SetField(fieldCountry, TextAfter(Page.GetString(5), 'Nacion = '));
  311.   SetField(fieldDirector, TextAfter(Page.GetString(6), 'Director = '));
  312.   SetField(fieldActors, TextAfter(Page.GetString(7), 'Actores = '));
  313.   SetField(fieldProducer, TextAfter(Page.GetString(8), 'Productor = '));
  314.   Comments := 'Gui≤n: ' + TextAfter(Page.GetString(9), 'Guion = ');
  315.   Comments := Comments + #13#10 + 'Fotografφa: ' + TextAfter(Page.GetString(10), 'Fotografia = ');
  316.   Comments := Comments + #13#10 + 'M·sica: ' + TextAfter(Page.GetString(11), 'Musica = ');
  317.   SetField(fieldComments, Comments);
  318.   LineNr := FindLine('Sinopsis = ', Page, 0);
  319.   Line := Page.GetString(LineNr);
  320.   strSinopsis := TextAfter(Line, 'Sinopsis = ');
  321.   LineNr := LineNr + 1;
  322.   Line := Page.GetString(LineNr);
  323.   while pos('URL = ', Line) = 0 do
  324.   begin
  325.     strSinopsis := strSinopsis + #13#10 + Line;
  326.     LineNr := LineNr + 1;
  327.     Line := Page.GetString(LineNr);
  328.   end
  329.   HTMLRemoveTags(strSinopsis);
  330.   SetField(fieldDescription, StringReplace(StringReplace(strSinopsis, 'ô', '"'), 'ö', '"'));
  331.   LineNr := FindLine('URL = ', Page, 0);
  332.   if LineNr <> -1 then
  333.     SetField(fieldURL, TextAfter(Page.GetString(LineNr), 'URL = '));
  334.   LineNr := FindLine('Imagen = ', Page, 0);
  335.   if LineNr <> -1 then
  336.     GetPicture(TextAfter(Page.GetString(LineNr), 'Imagen = '));
  337.   Page.Free;
  338. end;
  339.  
  340. begin
  341.   SetArrayLength(Articles,11);
  342.   Articles[0]:='Lo ';
  343.   Articles[1]:='La ';
  344.   Articles[2]:='Le ';
  345.   Articles[3]:='Uno ';
  346.   Articles[4]:='Una ';
  347.   Articles[5]:='Un ';
  348.   Articles[6]:='El ';
  349.   Articles[7]:='Los ';
  350.   Articles[8]:='Las ';
  351.   Articles[9]:='Unos ';
  352.   Articles[10]:='Unas ';
  353.  
  354. if CheckVersion(3,5,0) then
  355.    begin
  356.     MovieName := '';
  357.     MovieName := GetField(fieldTranslatedTitle);
  358.      donde := '&donde=1';
  359.      if MovieName = '' then
  360.       begin
  361.        MovieName := GetField (fieldOriginalTitle);
  362.        donde := '&donde=2';
  363.       end
  364.      if MovieName = '' then
  365.       begin
  366.        Input('Importar de Culturalia', 'Introduzca el Titulo de la Pelicula:', MovieName);
  367.        donde := '&donde=1';
  368.       end
  369.     If MovieName <> '' then
  370.       begin
  371.         // Eliminate spanish article if exists
  372.         for Index := 0 to 10 do
  373.         begin
  374.          if Pos(Articles[Index], MovieName) <> 0 then
  375.          MovieName := copy(MovieName, length(Articles[Index]), length(MovieName));
  376.         end;
  377.  
  378.         // Eliminate point(s) at final of MovieName before search
  379.         strTemp := MovieName;
  380.         if Copy(strTemp, Length(strTemp), Length(strTemp)) = '.' then
  381.           MovieName := Copy(strTemp, 1, Length(strTemp) -1);
  382.         AnalyzePageCulturalia(BaseURLCulturalia + '?catalogo=1&texto=' + UrlEncode(MovieName) + donde);
  383.         if (GetOption('ImportRatingIMDB')=1) or (GetOption('ImportLengthIMDB')=1) then
  384.           AnalyzePageIMDB('http://imdb.com/find?more=tt;q='+UrlEncode(GetField(fieldOriginalTitle)));
  385.       end;
  386.    end else
  387.      ShowMessage('Este script requiere una versi≤n mßs reciente de Ant Movie Catalog (al menos la versi≤n 3.5.0)');
  388. end.
  389.